Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diagnostics: do not suggest type name tweaks on type-inferred closure args #112325

Merged
merged 1 commit into from
Jun 6, 2023

Conversation

notriddle
Copy link
Contributor

Fixes #111932

@rustbot
Copy link
Collaborator

rustbot commented Jun 5, 2023

r? @eholk

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 5, 2023
@rust-log-analyzer

This comment has been minimized.

@notriddle notriddle force-pushed the notriddle/issue-111932 branch from 121527b to 2e9d957 Compare June 5, 2023 23:22
@rustbot
Copy link
Collaborator

rustbot commented Jun 5, 2023

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be such a heavy hammer? It really looks like we should just not be applying suggestions to closure arguments that have no type span -- that seemed to me to be the real issue with #111932.

We can still keep suggestions for closure args that do, like |x: dyn Trait| or whatever.

Or better yet, we apply them but make sure to apply them correctly...

fcx.require_type_is_sized(
param_ty,
param.pat.span,
traits::SizedArgumentType(ty_span.filter(|_| !tcx.is_closure(fn_def_id.into()))),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this into an if like below? Easier to read that way IMO

@notriddle
Copy link
Contributor Author

Does this need to be such a heavy hammer? It really looks like we should just not be applying suggestions to closure arguments that have no type span

It's complicated because hir::Param::ty_span isn't an Option, so it's not clear how to tell if a closure argument has a type ascription or not.

Would you rather HIR be changed to make ty_span an Option, and have it filled in as None when a closure argument doesn't have one?

@compiler-errors
Copy link
Member

That's one way of doing it. If you don't want to do that much work though, you can check if the ty_span is equal to the binding's span, perhaps like how dc2977e does it...

@notriddle notriddle force-pushed the notriddle/issue-111932 branch from 2e9d957 to 33bdca1 Compare June 6, 2023 00:50
@notriddle notriddle changed the title diagnostics: do not suggest type name tweaks on closure args diagnostics: do not suggest type name tweaks on type-inferred closure args Jun 6, 2023
@notriddle
Copy link
Contributor Author

That makes sense. I've pushed a new commit that does that.

@notriddle notriddle force-pushed the notriddle/issue-111932 branch from 33bdca1 to 3a2e4f7 Compare June 6, 2023 00:59
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me when green

@rust-log-analyzer

This comment has been minimized.

@notriddle notriddle force-pushed the notriddle/issue-111932 branch 2 times, most recently from 4379f7e to 8f06fbc Compare June 6, 2023 02:04
@notriddle notriddle force-pushed the notriddle/issue-111932 branch from 8f06fbc to 467bc9f Compare June 6, 2023 02:05
@notriddle
Copy link
Contributor Author

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Jun 6, 2023

📌 Commit 467bc9f has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 6, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 6, 2023
…r=compiler-errors

diagnostics: do not suggest type name tweaks on type-inferred closure args

Fixes rust-lang#111932
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 6, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#111058 (Correct fortanix LVI test print function)
 - rust-lang#111369 (Added custom risc32-imac for esp-espidf target)
 - rust-lang#111962 (Make GDB Python Pretty Printers loadable after spawning GDB, avoiding required `rust-gdb`)
 - rust-lang#112019 (Don't suggest changing `&self` and `&mut self` in function signature to be mutable when taking `&mut self` in closure)
 - rust-lang#112199 (Fix suggestion for matching struct with `..` on both ends)
 - rust-lang#112220 (Cleanup some `EarlyBinder::skip_binder()` -> `EarlyBinder::subst_identity()`)
 - rust-lang#112325 (diagnostics: do not suggest type name tweaks on type-inferred closure args)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 38c92cc into rust-lang:master Jun 6, 2023
@rustbot rustbot added this to the 1.72.0 milestone Jun 6, 2023
@notriddle notriddle deleted the notriddle/issue-111932 branch June 6, 2023 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

E0277 shows invalid help in closures
6 participants